/**
 * author:Administrator
 * date:2016/1/6
 * desc: 支付方式
 */

'use strict';
let Dao = require('./dao');
let F = require('./function');
let dispatcher = new Dao.orderPayWay();
var api = {};
exports.api = api;

/**
 * test
 * post /o2o_service/payway/v1/test
 * @param env
 */
api.test = function *(Env) {
  return F.returnMsg(200, '0k');
};

/**
 * 增加 一种支付方式
 * post /o2o_service/payway/v1/add
 {
 "order_id":1,
 "pay_way":2,
 "price":12.34,
 "coupon_code":"abcde",
 "return_data":"测试数据"
 }
 */
api.add = function*(Env) {
  Env.I = yield F.Init(Env, [1]);
  if (Env.I.errors) {
    return F.returnMsg(400, Env.I.errors.msg, Env.I.errors.level);
  }
  var fields = Env.I;


  let ret = yield dispatcher.add(fields);
  if (ret.error == 1) return F.returnMsg(400, ret.msg, 3);
  return F.returnMsg(200, ret.msg, 3, ret.data);
};

// update list detail
/**
 * 编辑 支付方式
 * post /o2o_service/payway/v1/update
 {
 	"act": 1,
 	"opy_id": 1,
 	"updateInfo": {
 		"pay_way": 2,
 		"price": 999.99,
 		"coupon_code": "xxxx",
 		"return_data": "测试数据2"
 	}
 }
 * @param Env
 */
api.update = function*(Env) {
  Env.I = yield F.Init(Env, [1]);
  if (Env.I.errors) {
    return F.returnMsg(400, Env.I.errors.msg, Env.I.errors.level);
  }
  var fields = Env.I;

  let ret = yield dispatcher.update(fields);
  if (ret.error == 1) return F.returnMsg(400, ret.msg, 3);
  return F.returnMsg(200, ret.msg, 3, ret.data);
};
/**
 * 获取 支付方式详情
 * post /o2o_service/payway/v1/detail
 {
 	"act": 1,
 	"opy_id": 1
 }
 * @param Env
 */
api.detail = function *(Env) {
  Env.I = yield F.Init(Env, [1]);
  if (Env.I.errors) {
    return F.returnMsg(400, Env.I.errors.msg, Env.I.errors.level);
  }
  var fields = Env.I;
  let ret = yield dispatcher.detail(fields);
  if (ret.error == 1) return F.returnMsg(400, ret.msg, 3);
  return F.returnMsg(200, ret.msg, 3, ret.data);
};